home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / bnews093.zip / cleanover.cmd < prev    next >
OS/2 REXX Batch file  |  1996-10-31  |  7KB  |  185 lines

  1. /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
  2. /*  Cleanover.cmd                                                           */
  3. /*  Cleans trash from *.over.txt files created by Bnews.                    */
  4.  
  5.   MIN_BODY_LINES = 100          /* Trash articles with less than this       */
  6.                                 /* number of lines in the message body      */
  7.                                 /* to help eliminate discussion and         */
  8.                                 /* keep only binary articles.               */
  9.  
  10.   drop keep.                    /* Stem variable of articles to keep.       */
  11.   drop trash.                   /* "                "        to trash.      */
  12.  
  13.                                 /* keep.0 and trash.0 are the total         */
  14.                                 /* number of items in the stem variables    */
  15.  
  16.   keep.0    = 6                 /* Number of items in stem variable keep.   */
  17.   keep.1    = ".AVI"            /* keep.1 to keep.x are strings to keep     */
  18.   keep.2    = ".MPG"            /* must be UPPER CASE                       */
  19.   keep.3    = ".MOV"
  20.   keep.4    = ".ZIP"
  21.   keep.5    = ".JPG"
  22.   keep.6    = ".GIF"
  23.  
  24.   trash.0   = 17                /* Number of items in stem variable trash.  */
  25.   trash.1   = "CASH"            /* trash.1 to trash.x are strings to trash  */
  26.   trash.2   = "*** DOT"         /* must be UPPER CASE                       */
  27.   trash.3   = ".WAV"
  28.   trash.4   = "BONDAGE"
  29.   trash.5   = "CLINTON"
  30.   trash.6   = "FREE"
  31.   trash.7   = "GAY"
  32.   trash.8   = "HOT TEEN"
  33.   trash.9   = "NIGGER"
  34.   trash.10  = "SCREENSAVER"
  35.   trash.11  = "SITE"
  36.   trash.12  = "SPAM"
  37.   trash.13  = "STRIP POKER"
  38.   trash.14  = "UPSKIRT"
  39.   trash.15  = "HOT MEN"
  40.   trash.16  = "MCARTH"
  41.   trash.17  = "STUD"
  42.  
  43.   fmask = '*.over.txt'                /* File mask of files to clean */
  44.  
  45.   signal on Halt
  46.   signal on NoValue
  47.  
  48.   drop file.
  49.   call SysFileTree fmask, 'file', 'f'   /* Find all matching files */
  50.   if file.0 = 0 then do
  51.     say ''
  52.     say 'No matching files:  'fmask
  53.     exit 0
  54.   end
  55.  
  56.   call SysCurState 'Off'
  57.  
  58.   call time 'e'
  59.  
  60.   trashcurrent = ""                       /* debug what gets trashed */
  61.  
  62.   do fcount = 1 to file.0                 /* Clean all matched files */
  63.     fnameover   = substr(file.fcount, 38)
  64.     fnametmp    = fnameover||'.clean.tmp'
  65.     fnametrash  = fnameover||'.trash'
  66.     notready = stream(fnameover, 'c', 'open')   /* check if file is ready */
  67.     if pos("NOTREADY", notready) \= 0 then do
  68.       say notready' 'fnameover
  69.     end
  70.     else
  71.       call Clean
  72.   end
  73.  
  74.   say "Elapsed time:  "time('e')
  75.   call SysCurState 'On'
  76.   return 0
  77.   /****************************************************************************/
  78.   /*  End of main                                                             */
  79.   /****************************************************************************/
  80.  
  81.  
  82.   /****************************************************************************/
  83.   /*  Clean reads each line of the file looking for lines to keep.            */
  84.   /*  If a line is found it is checked for trash.                             */
  85.   /*  If the line has no trash it is saved.                                   */
  86.   /****************************************************************************/
  87.   Clean:
  88.     cr = '0d'x                      /* carriage return                        */
  89.     call SysFileDelete fnametmp     /* delete old files if they exist         */
  90.     call SysFileDelete fnametrash
  91.     say '' ; say 'Cleaning 'fnameover
  92.     iline     = 0
  93.     ideleted  = 0
  94.     ikept     = 0
  95.     do while lines(fnameover) \= 0
  96.       line0 = linein(fnameover)         /* preserve case in line0             */
  97.       line  = translate(line0)          /* to upper case for comparison       */
  98.       iline = iline + 1                 /* no. lines read                     */
  99.  
  100.       bodylines = CountTabs()           /* trash articles < MIN_BODY_LINES    */
  101.       if bodylines < MIN_BODY_LINES & bodylines \= -1 then do
  102.         call lineout fnametrash, line0
  103.         ideleted = ideleted + 1         /* no. lines trashed                  */
  104.         call charout , cr'Lines read:  'iline'  Kept:  'ikept'  Trashed:  'ideleted
  105.         iterate
  106.       end
  107.  
  108.       ikeepline = 0                     /* keep flag                          */
  109.       do i = 1 to keep.0
  110.         if pos(keep.i, line) > 0 then   /* look for things to keep            */
  111.           ikeepline = Filter()          /* determine if its trash             */
  112.       end
  113.       if ikeepline == 1 then do         /* keep good articles                 */
  114.         call lineout fnametmp, line0
  115.         ikept = ikept + 1               /* no. lines kept                     */
  116.       end
  117.       else do                           /* discard trash                      */
  118.         call lineout fnametrash, line0
  119.         ideleted = ideleted + 1         /* no. lines trashed                  */
  120.       end
  121.                                         /* Show progress                      */
  122.       call charout , cr'Lines read:  'iline'  Kept:  'ikept'  Trashed:  'ideleted
  123.     end
  124.     say ''
  125.     call lineout fnameover              /* close files  */
  126.     call lineout fnametrash
  127.     call lineout fnametmp
  128.     fs = stream(fnametrash,'c','query size')
  129.     if fs == 0 then
  130.       call SysFileDelete fnametrash
  131.     call SysFileDelete fnameover
  132.    '@ren 'fnametmp' 'filespec('name', fnameover)
  133.     return 0
  134.  
  135.   /****************************************************************************/
  136.   /*  Filter looks at each line for trash.                                    */
  137.   /*  Returns: 0 if trash is found.                                           */
  138.   /*           1 if no trash is found.                                        */
  139.   /****************************************************************************/
  140.   Filter:                                 /* Look for trash */
  141.     do j = 1 to trash.0
  142.       if pos(trash.j, line) > 0 then do
  143.         trashcurrent = trash.j
  144.         return 0                          /* found trash */
  145.       end
  146.     end
  147.     return 1                              /* no trash */
  148.  
  149.   /****************************************************************************/
  150.   /* Count the tabs in the overview to find the number of lines in the        */
  151.   /* article body.                                                            */
  152.   /* Returns: number of lines in the message body                             */
  153.   /*          -1 if error                                                     */
  154.   /****************************************************************************/
  155.   CountTabs: procedure expose line
  156.  
  157.     i = 1
  158.     bodylines = -1;                 /* error flag, could not find body lines */
  159.  
  160.     i = pos('09'x||'09'x, line, i)  /* find the two tabs */
  161.     if i == 0 then
  162.       return bodylines
  163.  
  164.     i = pos('09'x, line, i+2)       /* next tab is the body lines */
  165.     if i == 0 then
  166.       return bodylines
  167.  
  168.     bodylines = substr(line, i+1, 10) /* extract body lines */
  169.  
  170.     p = pos('09'x, bodylines)         /* delete remaining */
  171.     if p \= 0 then
  172.       bodylines = delstr(bodylines, p, 99999)
  173.  
  174.     return bodylines
  175.  
  176.  
  177.   Halt:
  178.     say ''
  179.     say 'ouch...'
  180.     exit 1
  181.  
  182.   NoValue:
  183.     say 'novalue at line 'sigl
  184.     exit 0
  185.